package com.szholly.data.general.metadata.table;

import java.util.HashMap;

import org.springframework.stereotype.Component;

import com.szholly.utils.spring.SpringBeanFactory;
import com.szholly.data.general.Field;
import com.szholly.data.general.GlobalDataType;
import com.szholly.data.general.InterceptorTableBase;
import com.szholly.data.general.RowBase;
import com.szholly.data.general.metadata.IBaseTable;

/**
 * 组织机构表
 */
@Component("DATA_DEFULATDOMAIN")
public class DefulatDomainTable extends InterceptorTableBase implements IBaseTable {
	public final static String TABLE_NAME = "DATA_DEFULATDOMAIN";

	/**
	 * 获取单例对象
	 */
	public static DefulatDomainTable getSingleRef() {
		return (DefulatDomainTable) SpringBeanFactory.getBean("DATA_DEFULATDOMAIN");
	}

	@Override
	public String getMetadataTableName() {
		return TABLE_NAME;
	}

	@Override
	public String getMetadataTableAliasName() {
		return "默认字典表";
	}

	private HashMap<String, Field> fields;

	@Override
	protected HashMap<String, Field> fields() {
		if (fields == null) {
			fields = new HashMap<String, Field>();

			Field itemField = new Field();
			
			itemField = new Field();
			itemField.setFieldName(RowBase.FIELD_VERSION);
			itemField.setDataType(GlobalDataType.Int32);
			itemField.setFieldID(2);
			itemField.setFieldAliasName("数据版本");
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(RowBase.FIELD_COMPANY);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(3);
			itemField.setFieldAliasName("企业名称");
			itemField.setCanShow(false);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(RowBase.FIELD_SYSTEMNAME);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(3);
			itemField.setFieldAliasName("系统名称");
			itemField.setCanShow(false);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_ID);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(2);
			itemField.setFieldAliasName("机构ID");
			itemField.setIsKey(true);
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_DOMAINCAPTION);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(4);
			itemField.setFieldAliasName("组织机构名称");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_PID);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("父节点id");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_ORDER);
			itemField.setDataType(GlobalDataType.Int32);
			itemField.setFieldID(9);
			itemField.setFieldAliasName("排序字段");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_JB);
			itemField.setDataType(GlobalDataType.Int32);
			itemField.setFieldID(9);
			itemField.setFieldAliasName("机构级别");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);

			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_ISCHILD);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("是否为叶子节点");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_DOMAINNAME);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("字典域名称");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_DOMAINCODE);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("字典域代码");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_ISEDIT);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("是否可编辑");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_ISUSER);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("是否可用");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(DefulatDomainRow.FIELD_UNIT);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("字典单位");
			itemField.setCanShow(true);
			itemField.setAllowNull(true);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
		}
		return fields;
	}

	/**
	 * 表分组信息
	 */
	@Override
	public String getTableGroup() {
		return "Data框架";
	}

	@Override
	public String getCodeFieldName() {
		return DefulatDomainRow.FIELD_DOMAINCODE;
	}

	@Override
	public String getCaptionFieldName() {
		return DefulatDomainRow.FIELD_DOMAINCAPTION;
	}
	
	/**
	 * 获取级别字段名
	 */
	@Override
	public String getLevelFieldName(){
		return DefulatDomainRow.FIELD_JB;
	}
	
	/**
	 * 获取是否为叶子节点字段名
	 */
	@Override
	public String getIsChildFieldName() {
		return DefulatDomainRow.FIELD_ISCHILD;
	}

	@Override
	public String getIDFieldName() {
		return DefulatDomainRow.FIELD_ID;
	}

	@Override
	public String getPIDFieldName() {
		return DefulatDomainRow.FIELD_PID;
	}
	
	@Override
	public String getDomainFieldName() {
		return DefulatDomainRow.FIELD_DOMAINNAME;
	}

	@Override
	public boolean getIsCodeTable() {
		return true;
	}
	
	@Override
	public boolean getIsTreeTable() {
		return true;
	}

	@Override
	public boolean getIsManageCodeTable() {
		return true;
	}
	
	@Override
	public String getGUIDFieldName(){
		return DefulatDomainRow.FIELD_ID;
	}
	
	@Override
	public String getIsUsedFieldName(){
		return DefulatDomainRow.FIELD_ISUSER;
	}
	
	@Override
	public String getIsEditFieldName(){
		return DefulatDomainRow.FIELD_ISEDIT;
	}
	
	/**
	 * 获取字典的单位字段
	 */
	@Override
	public String getUnitFieldName() {
		return DefulatDomainRow.FIELD_UNIT;
	}
	
	@Override
	public String getOrderFieldName() {
		return DefulatDomainRow.FIELD_ORDER;
	}
}
